package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/10/05 23:13
 **/
public class Day34_4_Num173_BSTIterator {
    class BSTIterator {
        TreeNode list = null;

        public BSTIterator(TreeNode root) {
            parseTree(root);
        }

        private void parseTree(TreeNode node){
            if(node.right != null){
                parseTree(node.right);
            }
            node.right = list;
            list = node;
            if(node.left != null){
                parseTree(node.left);
            }
        }

        public int next() {
            int val = list.val;
            list = list.right;
            return val;
        }

        public boolean hasNext() {
            return list != null;
        }
    }
}